home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Tools / idle / ZoomHeight.py < prev   
Encoding:
Python Source  |  2000-06-23  |  1.1 KB  |  44 lines

  1. # Sample extension: zoom a window to maximum height
  2.  
  3. import re
  4. import sys
  5.  
  6. class ZoomHeight:
  7.  
  8.     menudefs = [
  9.         ('windows', [
  10.             ('_Zoom Height', '<<zoom-height>>'),
  11.          ])
  12.     ]
  13.  
  14.     windows_keydefs = {
  15.         '<<zoom-height>>': ['<Alt-F2>'],
  16.     }
  17.     unix_keydefs = {
  18.         '<<zoom-height>>': ['<Control-x><Control-z>'],
  19.     }
  20.  
  21.     def __init__(self, editwin):
  22.         self.editwin = editwin
  23.  
  24.     def zoom_height_event(self, event):
  25.         top = self.editwin.top
  26.         geom = top.wm_geometry()
  27.         m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
  28.         if not m:
  29.             top.bell()
  30.             return
  31.         width, height, x, y = map(int, m.groups())
  32.         newheight = top.winfo_screenheight()
  33.         if sys.platform == 'win32':
  34.             newy = 0
  35.             newheight = newheight - 72
  36.         else:
  37.             newy = 24
  38.             newheight = newheight - 96
  39.         if height >= newheight:
  40.             newgeom = ""
  41.         else:
  42.             newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
  43.         top.wm_geometry(newgeom)
  44.